package com.runmi.webchat.aftersale.config;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.runmi.webchat.aftersale.common.utils.HttpUtil;
import com.runmi.webchat.aftersale.common.utils.OkHttpUtil;
import com.runmi.webchat.aftersale.common.utils.StringUtil;

@Configuration
@PropertySource("classpath:wxconfig.properties")
public class WxConfig {
	
	protected static final Log log = LogFactory.getLog("logFile");
	
	@Value("${wx.appid}")
	private String appid;
	
	@Value("${wx.secret}")
	private String secret;
	

	public String getAccessToken(){
		String accessTocken="";
		String url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+ appid +"&secret=" + secret;
		String json= HttpUtil.doGetSSL(url, null);
		//{"access_token":"ACCESS_TOKEN","expires_in":7200}
		log.info("getAccessToken:" + json);
		if(StringUtil.isNotEmptyStr(json)){
			JSONObject jsonObject= JSON.parseObject(json);
			accessTocken=  jsonObject.get("access_token").toString();
		}
		return accessTocken;
	}
	
	

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public String getSecret() {
		return secret;
	}

	public void setSecret(String secret) {
		this.secret = secret;
	}
	
	
}
